package admin

import (
	_ "embed"
	. "go-caipu/pkg/services/sqlstore/migrator"
)

//go:embed sql/sys_dept.sql
var deptSQLByte []byte

func AddDeptMigrations(mg *Migrator) {
	userV1 := Table{
		Name: "sys_dept",
		Columns: []*Column{
			{Name: "dept_id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
			{Name: "parent_id", Type: DB_BigInt, Length: 4, Nullable: true},
			{Name: "dept_path", Type: DB_NVarchar, Length: 255, Nullable: false},
			{Name: "dept_name", Type: DB_NVarchar, Length: 255, Nullable: false},
			{Name: "sort", Type: DB_Int, Length: 4, Nullable: true},
			{Name: "leader", Type: DB_BigInt, Length: 4, Nullable: true},
			{Name: "phone", Type: DB_NVarchar, Length: 11, Nullable: true},
			{Name: "email", Type: DB_NVarchar, Length: 64, Nullable: true},
			{Name: "Status", Type: DB_Int, Length: 4, Nullable: true},
			{Name: "remark", Type: DB_NVarchar, Length: 300, Nullable: true},

			{Name: "create_by", Type: DB_BigInt, Nullable: false},
			{Name: "update_by", Type: DB_BigInt, Nullable: true},
			{Name: "created_at", Type: DB_DateTime, Nullable: false},
			{Name: "updated_at", Type: DB_DateTime, Nullable: true},
		},
		Indices: []*Index{
			{Cols: []string{"sys_dept"}, Type: UniqueIndex},
		},
	}
	//create table
	mg.AddMigration("create sys_dept table", NewAddTableMigration(userV1))

	//插入默认数据
	//sqlPath := filepath.Join(util.GetProgramPath(), "/pkg/services/sqlstore/migrations/admin/sql/sys_dept.sql")
	//content, err := os.ReadFile(sqlPath)
	//if err != nil {
	//	panic(fmt.Sprintf("read sql file:sys_dept.sql path:%s err:%s", sqlPath, err.Error()))
	//}
	mg.AddMigration("insert into sys_dept", NewRawSQLMigration(string(deptSQLByte)))
}
